package org.jmat.service;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.jmat.service.PersonServiceStub.GetPersonById;
import org.jmat.service.PersonServiceStub.GetPersonByIdResponse;
import org.jmat.service.PersonServiceStub.Person;

public class PersonManager {
	
	/**
	 * Call the getAllUsers method of the web services
	 * @return
	 */
	public Person[] getAllUsers(){
		Person[] allUsersReturn = null;
		try {
			PersonServiceStub stub = new PersonServiceStub("http://192.168.0.11:8080/axis2/services/PersonService");			
			PersonServiceStub.GetAllUsersResponse allUsers = stub.getAllUsers();
			allUsersReturn = allUsers.get_return();
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return allUsersReturn;
	}
	
	/**
	 * Call the getPersonById method of the web services
	 * @param id
	 * @return
	 */
	public Person getPersonById(int id){
		PersonServiceStub stub;
		Person p = null;
		try {
			stub = new PersonServiceStub("http://192.168.0.11:8080/axis2/services/PersonService");
			GetPersonById request = new GetPersonById();
			request.setId(1);
			GetPersonByIdResponse response = stub.getPersonById(request);
			p = response.get_return();
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return p;
	}
	

}
